<?php
include($folder.'/layouts/code-behind/backend.php');
function blc_galeriak_select_count()
{
	return queryScalar('SELECT COUNT(*) FROM gallery WHERE gallery_id IS NOT NULL', null);
}
function blc_galeriak_select($from, $itemsPerPage, $sortColumn, $sortDirection)
{
	$orderBy = $sortColumn.'_'.$sortDirection;
	return
		query(
		'SELECT 
			actual.name AS actualName, 
			actual.id AS actualID, 
			parent.name AS parentName 
		FROM gallery AS actual 
			LEFT OUTER JOIN gallery AS parent ON actual.gallery_id = parent.id 
			WHERE actual.gallery_id IS NOT NULL 
			ORDER BY 
				CASE WHEN :orderBy = \'parentName_asc\' THEN parent.name END ASC,
				CASE WHEN :orderBy = \'parentName_desc\' THEN parent.name END DESC,
				CASE WHEN :orderBy = \'actualName_asc\' THEN actual.name END ASC,
				CASE WHEN :orderBy = \'actualName_desc\' THEN actual.name END DESC
			LIMIT :from,:itemsPerPage',
		array('from'=>$from, 'itemsPerPage'=>$itemsPerPage, 'orderBy'=>$orderBy));
}
$master['action'] = null;
$master['attributes'] = null;
$master['pageTitle'] = 'Galériák';
?>